﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace _017_Socket编程_TCP协议
{
    class Program
    {
        static void Main(string[] args)
        {
            //1、创建socket
            Socket tcpServer = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
            //2、绑定ip、端口号
            IPAddress ipAddress = new IPAddress(new byte[] {192, 168, 31, 202});
            EndPoint point = new IPEndPoint(ipAddress,7788);//对ip和端口号进行封装
            tcpServer.Bind(point);
            //3、开始监听，等待客户端连接
            tcpServer.Listen(100);//参数:最大连接数
            Socket clientSocket = tcpServer.Accept();//暂停当前线程，直到有一个客户端连接
            // 用返回的socket和客户端做通讯
            clientSocket.Send(Encoding.UTF8.GetBytes("哈喽 欢迎连接！"));

            Console.ReadKey();
        }
    }
}
